<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<!-- saved from url=(0055)http://portal.moretv.com.cn/mportal/weixin_v2/play.html -->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:funcs="xalan://com.downjoy.app.netgame.common.util.XSLTFuncs"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>遥控器</title>
    <link rel="stylesheet" type="text/css" href="./files/css.css">
    <script type="text/javascript" src="./files/jquery.min.js"></script>
    <script type="text/javascript" src="./files/utils.js"></script>
    <script type="text/javascript" src="./files/main.js"></script>
    <script>
        /*document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            WeixinJSBridge.call('hideToolbar');
            WeChatHelperConstants.WeiXinJSBridge = WeixinJSBridge;
        });*/
    </script>
    <style type="text/css">
        .input-test{
            width: 95%;
            position: absolute;
            top:65px;

        }
        .input-test input{
            width: 79%;
            position: relative;
            float: left;
            line-height: 18px;
            height: 18px;

        }
        .input-test a{
            float: right;
            width: 15%;
            position: relative;
            display: block;
            background: #7B7F86;
            border-radius: 5px;
            font-size: 14px;
            color: #ccc;
            height: 42px;
            line-height: 42px;

        }
        .input-test a:hover{background: #0a0a0a;}
        @media screen and (max-width: 320px){
            .input-test a{height: 34px;
                line-height: 34px;}

        }
    </style>
</head>
<body style="background: #2b2b2a; min-height:100%;">
<div class="touchArea" id="touch_area"></div>
<div class="pointer" id="pointer"></div>
<div class="pointer2" id="pointer2"></div>
<div class="Arrow arrowUp" id="arrow_Up"></div>
<div class="Arrow arrowDown" id="arrow_Down"></div>
<div class="Arrow arrowLeft" id="arrow_Left"></div>
<div class="Arrow arrowRight" id="arrow_Right"></div>
<div class="prompt_bg"></div>
<div class="tip" id="conflict">
    <div class="tips"><i>&nbsp;</i><span id="tip_text">设备正被其它终端控制，请重新推送播放</span></div>
</div><!--end prompt-->
<div class="prompt" id="pin">
    <div class="title">请输入电视上的设备码</div>
    <div class="content">
        <div class="pin">        	
            <a href="javascript:void(0)" class="close">关闭</a>
            <div class="warm"><span>*</span>设备码位置：SimKey&gt;设置&gt;助手&amp;微信
            </div>
            <input type="text" placeholder="请输入电视上的设备码" id="pin_code">
            <div class="button">
            	<a href="javascript:void(0);" class="cancel">取消</a>
                <a href="javascript:simKeyUrlpinEnter();" class="join">连接</a>
            </div>
            <div class="sure"><span>&nbsp;</span>确保手机和电视处于同一路由下</div>
            <div class="sure"><span>&nbsp;</span>未安装SimKey，需要安装才可以使用</div>
        </div><!--end pin-->
    </div><!--end contetn-->
</div><!--end prompt-->
<div class="prompt" id="alert">
    <div class="title"><i>&nbsp;</i>推送失败</div>
    <div class="content">
        <div class="pin alert">
            <a href="javascript:void(0)" class="close">关闭</a>
            <div class="warm ">1、请确认手机通过WiFi上网。<br>2、如多次推送失败，请先启动电视猫或切换设备后再推送。</div>
            <div class="button b1">
                <a href="javascript:cancelAlert();" class="textShadow">知道了</a>
            </div>
            <div class="button b2">
                <a href="javascript:popInputPin();" class="textShadow">切换设备</a>
            </div>
        </div><!--end pin-->
    </div><!--end contetn-->
</div><!--end prompt-->
<div class="prompt" id="network_alert">
    <div class="title"><i>&nbsp;</i>推送失败</div>
    <div class="content">
        <div class="pin alert">
            <a href="javascript:void(0)" class="close">关闭</a>
            <div class="warm ">您当前处于2G/3G网络，无法推送到电视播放，请切换到WIFI网络后再试</div>
            <div class="button b1" style="width:100%;">
                <a href="javascript:cancelNetWorkAlert();" class="textShadow">知道了</a>
            </div>

        </div><!--end pin-->
    </div><!--end contetn-->
</div><!--end prompt-->
<div class="header absolute header2 " style="z-index: 30">
    <div class="moreTv" style="display: block;">
        <div class="left">
            <span class="logo">&nbsp;</span>
            <div class="text">
                <p class="">SimKey(手机版)</p>
                <p class="">看电视就该如此轻松</p>
            </div>
        </div><!--end left-->
        <div class="right">
            <a href="./software/SimKey.apk" class="install">下载</a>
            <a href="javascript:void(0)" class="close">&nbsp;</a>
        </div><!--end right-->
    </div><!--end moreTv-->
    <h1 class="controlTitle">
        <a href="javascript:window.history.go(-1);" class="controlBack" style="display: none;">返回</a>
        <!--<div class="input-test">-->
            <!--<input type="text" id="test_text"/>-->
            <!--<a href="javascript:testInput();">确定</a>-->
        <!--</div>-->
        <div class="text" id="selectTv"><span>未连接设备</span><i></i></div>
        <div class="deviceBox">
            <i class="arrow"></i>
            <ul id="mydevices"><li onclick="javascript:popInputPin();" id="addBoxes"><i class="add">&nbsp;</i><span>添加新设备</span></li></ul>
        </div><!--end deviceBox-->
    </h1>
</div><!--end header-->
<div class="controllerTip" style="display: block;">&nbsp;</div>
<div class="controller">
    <div class="footer" id="footerMenu">
        <ul>
            <li>
                <div id="home_menu" onclick="javascript:touchEventPush(&#39;Home&#39;);">
                    <i class="home"></i>
                </div>
            </li>
            <li class="toBack">
                <div id="esc_menu" onclick="javascript:touchEventPush(&#39;Esc&#39;);">
                    <i class="back"></i>
                </div>
            </li>
            <li>
                <div id="menu_menu" onclick="javascript:touchEventPush(&#39;Menu&#39;);">
                    <i class="menu"></i>
                </div>
            </li>
        </ul>
    </div><!--end footer-->
</div><!--end controller-->

<script type="text/javascript">
    $('.controllerTip').click(function(){
        $('.controllerTip').css('display','none');
        setCookie('tipFlag','false');
    });
    if(null == getCookie('tipFlag')){
        $('.controllerTip').css('display','block');
    }
    var showFlag = moreTVHelperShowOrHide();
    if(showFlag){
        $('.moreTv').css('display','block');
    }else{
        $('.moreTv').css('display','none');
        setCookie(showHideFlagKey,'-1');
        $(".header").removeClass("header2");
    }
    var urls = getUrlParams();
    var userName= urls.userName;
    if(userName){
        $('.controlBack').css('display','block');
        setCookie('userName',userName);
    }else{
        $('.controlBack').css('display','none');
        userName = getCookie('userName');
        if(!userName){
            userName = WeChatHelperConstants.RandomUserNamePrefix + Math.uuid();
            setCookie('userName',userName);
        }
    }
    //refreshDevices();
    var devices = JSON.parse(getCookie(DevicesLocalKey) || null);
    //refreshDevices(devices,null);
    if(urls.pSid || urls.sSid){
        WeChatHelperConstants.DetailpSid = urls.pSid;
        WeChatHelperConstants.DetailsSid = urls.sSid;
        WeChatHelperConstants.DetailContentType = urls.contentType;
        WeChatHelperConstants.DetailPlayType = urls.playType;
    }
    var from = urls.from;
    if(from && from == WeChatHelperConstants.DetailPageFrom.WeiXinSearch){
        if(typeof urls.playType != 'undefined'){

        }else{
            upLog(WeChatHelperConstants.LogType.RemoteControl,'page_remoteControl');//微信客户端直接跳转到遥控器页面

            //WeChatHelperConstants.CurrentEventType = WeChatHelperConstants.EventType.MobileRemoteControl;
            //connectAuthenticate({eventType:WeChatHelperConstants.EventType.GetCurrentDevice});
        }
    }else{
        //connectAuthenticate({eventType:WeChatHelperConstants.EventType.GetCurrentDevice});
    }
    /*autoConnect(function(devices,device){
        refreshDevices(devices,device);
        if(from && from == WeChatHelperConstants.DetailPageFrom.WeiXinSearch && typeof urls.playType != 'undefined'){
            gotoPlay(urls.pSid,urls.sSid,urls.contentType,urls.playType,urls.title);//微信客户端直接搜索直播后跳转到遥控器页面
        }
    });*/

    /*
    if(from && (from == WeChatHelperConstants.DetailPageFrom.WeiXinRecommend || from == WeChatHelperConstants.DetailPageFrom.WeiXinSearch)){
        autoConnect(function(devices,device){
            refreshDevices(devices,device);
            if(from == WeChatHelperConstants.DetailPageFrom.WeiXinSearch && typeof urls.playType != 'undefined'){
                gotoPlay(urls.pSid,urls.sSid,urls.contentType,urls.playType,urls.title);//微信客户端直接搜索直播后跳转到遥控器页面
            }
        });
    }
    */

    var x1,x2,y1,y2;
    var touchDownTimer = null;
    var longTouchDownCount = 0;
    var _touchMove = false;
    $(function () {
        var ele = document.getElementById('touch_area');
        ele.addEventListener('touchstart', touchStart, false);
        ele.addEventListener('touchmove', touchMove, false);
        ele.addEventListener('touchend', touchEnd, false);
        $('#footerMenu').find("div").bind("touchstart",function(){
            menuTouchStart($(this));
        });
        $('#footerMenu').find("div").bind("touchend",function(){
            menuTouchEnd($(this));
        });
    });
    function menuTouchStart(_obj){
        _obj.attr("class","on");

    }
    function menuTouchEnd(_obj){
        _obj.attr("class","");
    }
    function touchStart(eve) {
        if($('.deviceBox').css('display') == 'block'){
            return;
        }
        longTouchDownCount=0;
        clearInterval(touchDownTimer);
        touchDownTimer = null;
        touchDownTimer = setInterval(touchPlayControl,100);
        var point = eve.touches[0];
        x1 = point.pageX-50;
        y1 = point.pageY-50;
        $('#pointer').css({'left':x1+'px','top':y1+'px','display':'block'});
        $('#pointer2').css({'left':(x1-50)+'px','top':(y1-50)+'px','display':'none'});
        eve.preventDefault();
        touchStartShow();
    }

    function touchMove(eve) {
        if($('.deviceBox').css('display') == 'block'){
            return;
        }
        _touchMove = true;
        eve.preventDefault();
        var point = eve.touches[0];
        longTouchDownCount = 0;
        x2 = point.pageX-50;
        y2 = point.pageY-50;
        $('#pointer').css({'left':x2+'px','top':y2+'px'});
        $('#pointer2').css({'left':(x2-50)+'px','top':(y2-50)+'px'});
    }

    function touchEnd(eve) {
        if($('.deviceBox').css('display') == 'block'){
            $(".deviceBox").slideUp(300);
            return;
        }
        clearInterval(touchDownTimer);
        touchDownTimer = null;
        longTouchDownCount = 0;
        $('#pointer').css('display','none');
        var direct = getDirect();
        _touchMove = false;
        if(direct){
            if (direct != 'Enter') {
                $('#pointer2').css('display','none');
                $('.Arrow').css('display', 'none');
                $('#arrow_' + direct).fadeIn(300, function () {
                    setTimeout(function () {
                        $('#arrow_' + direct).fadeOut(200);
                    }, 300);
                });
            }else{
                $('#pointer').css('display','block');
                $('#pointer2').fadeIn(200,function(){
                    $('#pointer2').css('display','none');
                    $('#pointer').css('display','none');
                });
            }
            touchEventPush(direct);
        }
    }

    function touchPlayControl(){
        if(_touchMove){
            longTouchDownCount++;
            if(longTouchDownCount>1){
                $('#count').html(longTouchDownCount);
                var direct = getDirect();
                if(direct && (direct=='Left' || direct=='Right' || direct=='Up' || direct=='Down')){
                    $('#pointer').css('display','block');
                    if($('#pointer2').css('display') == 'none'){
                        $('#pointer2').fadeIn(200);
                    }
                    touchEventPush(direct);
                }

            }
        }else{
            longTouchDownCount = 0;
        }
    }
    function getDirect(){
        var direct = '';
        if(!_touchMove){
            return WeChatHelperConstants.DirectValue.Enter;
        }
        var x = x2-x1;
        var y = y2-y1;
        if(x>0){
            var xx = Math.abs(x);
            var yy = Math.abs(y);
            if(yy == 0){
                direct = WeChatHelperConstants.DirectValue.Right;
            }else{
                if(yy > xx){
                    if(y<0){
                        direct = WeChatHelperConstants.DirectValue.Up;
                    }else{
                        direct = WeChatHelperConstants.DirectValue.Down;
                    }
                }else if(yy < xx){
                    direct = WeChatHelperConstants.DirectValue.Right;
                }
            }
        }else if(x <0){
            var xx = Math.abs(x);
            var yy = Math.abs(y);
            if(yy == 0){
                direct = WeChatHelperConstants.DirectValue.Left;
            }else{
                if(yy > xx){
                    if(y<0){
                        direct = WeChatHelperConstants.DirectValue.Up;
                    }else{
                        direct = WeChatHelperConstants.DirectValue.Down;
                    }
                }else if(yy < xx){
                    direct = WeChatHelperConstants.DirectValue.Left;
                }
            }

        }else{
            if(y > 0){
                direct = WeChatHelperConstants.DirectValue.Down;
            }else if(y < 0){
                direct = WeChatHelperConstants.DirectValue.Up;
            }
        }
        return direct;
    }
    function touchEventPush(_direct){
        /*
        var uids = getCookie(UIDKey);
        if(uids){
            var current_uid = uids.split(',')[0];
            var infos = getCookie(uidPref+current_uid);
            if (infos) {
                var infoArr = infos.split(',');
                if (infoArr.length > 0) {
                    WeChatHelperConstants.CurrentDeviceObj = {
                        ip: infoArr[0],
                        port: infoArr[1],
                        name: infoArr[2],
                        userid: current_uid,
                        clientId: infoArr[3],
                        url: infoArr[0] + ':' + infoArr[1]
                    }
                }
            }
        }
        if (WeChatHelperConstants.CurrentDeviceObj) {
            var params = {
                eventType: WeChatHelperConstants.EventType.MobileRemoteControl,
                operate: 'wx-' + WeChatHelperConstants.WeChatOperate.direct,
                param: _direct,
                param2: {eventType: WeChatHelperConstants.EventType.MobileRemoteControl, params: JSON.stringify({'keyName': _direct})}
            };
            connectAuthenticateCallBack(params, WeChatHelperConstants.CurrentDeviceObj);
        }

        var para = {
            Action : WeChatHelperConstants.Action.Event,
            eventType: WeChatHelperConstants.EventType.MobileRemoteControl,
            params: JSON.stringify({'keyName': _direct})
        }*/

        var devicesimkey = JSON.parse(getSimKeyCookie(CurrentDevicesSimKeyUrl) || null);
        if(devicesimkey == null || devicesimkey.deviceAddr == ""){
            alert("请添加设备");
        }else{
            var url = "http://" + devicesimkey.deviceAddr + "/SimKey";
            var _data = {"mKeyID": GetAndroidKeyCode(_direct), "mDeviceID":"IP123"};
             $.ajax({url:url,
                     type:'POST',
                     timeout:6000, //超时时间设置，单位毫秒
                     data:JSON.stringify(_data),
                     dataType:'json',
                     async:false,
                     error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log(errorThrown);
                     }
             });

        }
       // playControl(para);
    };

    function touchStartShow(){
        /*
        var uids = getCookie(UIDKey);
        if(uids){
            var current_uid = uids.split(',')[0];
            var infos = getCookie(uidPref+current_uid);
            if (infos) {
                var infoArr = infos.split(',');
                if (infoArr.length > 0) {
                    WeChatHelperConstants.CurrentDeviceObj = {
                        ip: infoArr[0],
                        port: infoArr[1],
                        name: infoArr[2],
                        userid: current_uid,
                        clientId: infoArr[3],
                        url: infoArr[0] + ':' + infoArr[1]
                    }
                }
            }
        }
        if (WeChatHelperConstants.CurrentDeviceObj) {
            var params = {
                eventType: WeChatHelperConstants.EventType.MobileRemoteControl,
                operate: 'wx-' + WeChatHelperConstants.WeChatOperate.show,
                param: '',
                param2: {eventType: WeChatHelperConstants.EventType.MobileRemoteControl, params: JSON.stringify({'keyName': ''})}
            };
            connectAuthenticateCallBack(params, WeChatHelperConstants.CurrentDeviceObj);

        }
        */
        var para = {
            Action : WeChatHelperConstants.Action.Event,
            eventType: WeChatHelperConstants.EventType.MobileRemoteControl,
            params: JSON.stringify({'keyName': ''})
        }
        playControl(para);
    }
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.call('hideToolbar');
        WeChatHelperConstants.WeiXinJSBridge = WeixinJSBridge;
    });
    $(".controllerTip").click(function(){
        $(this).fadeOut(300);
    });
    $("#selectTv").click(function(e){
        e = event || window.event;
        $(".deviceBox").slideToggle(300);
        e.stopPropagation();
    });

    $(function(){
        var tmpdeviceSimKeys = JSON.parse(getSimKeyCookie(DevicesSimKeyUrl) || null);
        console.log(tmpdeviceSimKeys);
        refreshSimKeyDevices(tmpdeviceSimKeys, null);
    });

    function testInput(){
        var _val = $('#test_text').val();
        if(!_val){
            return;
        }
        var para = {
            Action : Action.Event,
            eventType: EventType.SpeakControl,
            params: JSON.stringify({'speak_event': _val})
        }
        playControl(para);
    };
    //bindDeviceChangeEvent();
</script>
</body></html>